/*
 * @Author: nqx2007 fenglimima334@163.com
 * @Date: 2023-12-06 14:48:33
 * @LastEditors: nqx2007 fenglimima334@163.com
 * @LastEditTime: 2023-12-12 20:03:54
 * @FilePath: /operator-manager/src/services/index.ts
 * @Description: 接口
 */
import { request } from '@umijs/max';
// import { MD5 } from 'crypto-js';

export const baseApiPrefix = '/api/product-certificate';

/*-------------------------登录相关的接口【开始】---------------------------------*/
//登录
export const login = (options: Record<string, any> = {}) => {
  const {
    data: { userName, passWord },
    ...rest
  } = options;
  const url = `${baseApiPrefix}/user/login`;
  return request(url, {
    method: 'POST',
    ...rest,
    data: {
      type: 3, // 3代表是小二后台
      userName,
      passWord,
      // passWord: MD5(passWord).toString(),
    },
  });
};
//退出登录
export const logout = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/user/logout`;
  return request(url, {
    method: 'GET',
    ...options,
  });
};
// 获取当前登录的用户信息
export const getUserInfo = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/user/user_info`;
  return request(url, {
    method: 'GET',
    ...options,
  });
};
// 检查手机号是否注册
export const phoneIsValid = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/user/check_mobile`;
  return request(url, {
    method: 'POST',
    ...options,
  }).then((res) => {
    return res?.success ? true : false;
  });
};
// 向手机号发送验证码
export const phoneForSend = (options: Record<string, any> = {}) => {
  const {
    params: { mobile },
    ...rest
  } = options;
  const url = `${baseApiPrefix}/user/send_sms/${mobile}`;
  return request(url, {
    method: 'GET',
    ...rest,
  });
};
// 校验短信验证码
export const validateCode = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/user/check_code`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
//重置密码
export const updatePassword = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/user/update_pwd`;
  const { data, ...rest } = options;
  return request(url, {
    method: 'POST',
    ...rest,
    data: {
      ...data,
      type: 3, // 3代表是小二后台
    },
  });
};
// 获取当前登录用户的菜单信息
export const getRemoteMenu = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/menu/list`;
  return request(url, {
    method: 'GET',
    ...options,
  }).then((res) => {
    return res?.success ? res?.data : [];
  });
};
/*-------------------------------登录相关的接口【结束】--------------------------------------------*/

/*--------------------------------优惠券管理相关接口【开始】----------------------------------------*/
//获取自营优惠券列表
export const getSelfCouponList = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/coupon/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
//获取代理优惠券列表
export const getAgentCouponList = (
  options: Record<string, any> = {},
) => {
  const url = `${baseApiPrefix}/coupon/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
// 获取购买优惠券列表
export const getBuyCouponList = (
  options: Record<string, any> = {},
) => {
  const url = `${baseApiPrefix}/coupon/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
/**-------------------------------优惠券管理相关的接口【结束】-------------------------------------- */
/*-------------------------------客户管理相关接口【开始】-------------------------------------------*/
// 获取用户（客户）列表
export async function getClientsList(options?: Record<string, any>) {
  return request(`${baseApiPrefix}/app/user/page`, {
    method: 'POST',
    ...(options || {}),
  });
}
/*-------------------------------客户管理相关的接口【结束】--------------------------------------------*/
/*-------------------------------商家管理相关接口【开始】-------------------------------------------*/
//获取申请入驻的商家列表
export function getAuditBusinessList(options: Record<string, any> = {}) {
  const url = `${baseApiPrefix}/business/apply/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
}
//获取需要审核的商家的详细信息
export const getBusinessDetail = (options: Record<string, any> = {}) => {
  const { params, ...rest } = options;
  const url = `${baseApiPrefix}/business/apply/detail/${params?.id}`;
  return request(url, {
    method: 'GET',
    ...rest,
  });
};
// 获取企业性质和所属行业的列表数据
export const getDictList = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/dictory/list`;
  return request(url, {
    method: 'POST',
    ...options,
  }).then((res) => {
    return res?.success ? res?.data : [];
  });
};
// 提交审核结果
export const submitAuditResult = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/business`;
  return request(url, {
    method: 'PUT',
    ...options,
  });
};
//获取已经入驻的商家列表
export function getBusinessList(options: Record<string, any> = {}) {
  const url = `${baseApiPrefix}/business/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
}
//更新商家的状态
export const updateBusinessStatus = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/business/update_status`;
  return request(url, {
    method: 'PUT',
    ...options,
  });
};
/*-------------------------------商家管理相关接口【结束】------------------------------------------*/
/*-------------------------------订单管理相关接口【开始】------------------------------------------*/
//获取个人订单列表
export const getPersonalOrderList = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/individual_order/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
//获取商家订单列表
export const getBusinessOrderList = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/business_order/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
/*--------------------------------订单管理相关接口【结束】----------------------------------------*/


/**-------------------------------账号权限相关的接口【开始】-------------------------------------- */
//获取账号列表
export const getAccountList = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/user/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
//获取不分页的角色列表，用于创建账号
export const getAllRoles = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/role/query_list`;
  return request(url, {
    method: 'GET',
    ...options,
  }).then((res) => {
    return res?.success ? res.data : [];
  });
};
// 创建账号
export const accountCreate = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/user`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
// 编辑账号
export const accountUpdate = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/user`;
  return request(url, {
    method: 'PUT',
    ...options,
  });
};
//修改账号状态
export const accountStatusUpdate = (options: Record<string, any> = {}) => {
  const {
    data: { id, status },
    ...rest
  } = options || {};
  const url = `${baseApiPrefix}/user/${id}/${status}`;
  return request(url, {
    method: 'PUT',
    ...rest,
  });
};
//获取角色列表
export const getRolesList = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/role/page`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
//创建角色
export const roleCreate = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/role`;
  return request(url, {
    method: 'POST',
    ...options,
  });
};
// 获取角色详情
export const getRoleDetail = (options: Record<string, any> = {}) => {
  const {
    data: { id },
    ...rest
  } = options;
  const url = `${baseApiPrefix}/role/${id}`;
  return request(url, {
    method: 'GET',
    ...rest,
  }).then((res) => {
    return res?.success ? res?.data : {};
  });
};
//编辑角色
export const roleUpdate = (options: Record<string, any> = {}) => {
  const url = `${baseApiPrefix}/role`;
  return request(url, {
    method: 'PUT',
    ...options,
  });
};
//删除角色
export const roleDelete = (options: Record<string, any> = {}) => {
  const {
    data: { id },
    ...rest
  } = options;
  const url = `${baseApiPrefix}/role/${id}`;
  return request(url, {
    method: 'DELETE',
    ...rest,
  });
};
//获取角色权限树
export const getRoleTreeData = () => {
  const url = `${baseApiPrefix}/menu/list`;
  return request(url).then((res) => {
    return res?.success ? res?.data : [];
  });
};
/**---------------------------------账号权限相关的接口【结束】--------------------------------------- */
